/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.cms.content.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeeplus.cms.support.validation.PatternExtend;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import com.jeeplus.core.persistence.DataEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;

import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 发布内容表Entity
 *
 * @author Sawyer
 * @version 2020-11-22
 */

@Getter
@Setter
@ToString
public class CmsContents extends DataEntity<CmsContents> {

    private static final long serialVersionUID = 1L;

    @Length(min = 1, max = 127, message = "标题长度必须介于 1 和 127之间")
    @ExcelField(title = "标题", align = 2, sort = 3)
    private String title;

    @ExcelField(title = "标题颜色", align = 2, sort = 4)
    private String color;

    @ExcelField(title = "封面图片", align = 2, sort = 5)
    @PatternExtend(regexp = "^.{1,3000}$", message = "封面图片路径最大长度不能超过3000")
    private String image;

    @ExcelField(title = "视频", align = 2, sort = 6)
    private String video;

    @ExcelField(title = "关键字", align = 2, sort = 7)
    @PatternExtend(regexp = "^.{1,250}$", message = "关键字最大长度不能超过250")
    private String keywords;

    @ExcelField(title = "描述摘要", align = 2, sort = 8)
    @PatternExtend(regexp = "^.{1,1000}$", message = "描述最大长度不能超过1000")
    private String description;

    @PatternExtend(regexp = "^[0-1]$", required = true, message = "首页轮播标记无效")
    @ExcelField(title = "首页轮播标记", align = 2, sort = 9)
    private String carouselFlag;

    @ExcelField(title = "轮播图片", align = 2, sort = 10)
    @PatternExtend(regexp = "^.{1,3000}$", message = "轮播图片路径最大长度不能超过3000")
    private String carouselImage;

    @PatternExtend(regexp = "^[0-1]$", required = true, message = "首页推荐标记无效")
    @ExcelField(title = "首页推荐标记", align = 2, sort = 11)
    private String recomFlag;

    @ExcelField(title = "推荐图片", align = 2, sort = 12)
    @PatternExtend(regexp = "^.{1,3000}$", message = "推荐图片路径最大长度不能超过3000")
    private String recomImage;

    @ExcelField(title = "置顶权重", align = 2, sort = 13)
    private Integer topWeight;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ExcelField(title = "置顶期限", align = 2, sort = 14)
    private Date topDate;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ExcelField(title = "发布时间", align = 2, sort = 15)
    private Date releaseDate;

    @ExcelField(title = "正文内容", align = 2, sort = 16)
    private String contents;

    @ExcelField(title = "点击数", align = 2, sort = 17)
    private Integer hits;

    @ExcelField(title = "来源网站名", align = 2, sort = 18)
    @PatternExtend(regexp = "^.{1,60}$", message = "网站名最大长度不能超过60")
    private String copyfromSite;

    @URL(message = "来源URL无效")
    @ExcelField(title = "来源URL", align = 2, sort = 19)
    private String copyfromUrl;


    @NotNull(message = "所属栏目不能为空")
    private String columnId;

    private String columnName;
    private String contentTypeId;
    private String contentTypeName;

    private Integer sort;

    /**
     * 所属站点,不在界面上显示，隐性关联
     */
    private String siteId;

    public CmsContents() {
        super();
        this.setIdType(IDTYPE_AUTO);
    }

    public CmsContents(String id) {
        super(id);
    }

    /**
     * 初始化数据
     */
    public void init() {
        this.setHits(0);
        this.setTopWeight(null == this.getTopWeight() ? 0 : this.getTopWeight());
        this.setTopDate(null == this.getTopDate() ? new Date() : this.getTopDate());
        this.setReleaseDate(null == this.getReleaseDate() ? new Date() : this.getReleaseDate());
    }
}
